package com.views {
	import com.Controller;
	import com.Data;
	import com.SuperBase;
	import com.SuperSubBase;
	import com.View;
	import com.data.IData;
	import com.utils.LoadResponder;
	import com.views.structure.Popup;
	import com.views.structure.Structure;

	public class Base extends SuperSubBase {
		protected var _instanceName:String;
		protected var _view:View;
		protected var _ctrl:Controller;
		protected var _data:IData;
		protected var _structure:Structure;
		protected var _popup:Popup;
		protected var _ignoreKeyboardEvent:Boolean = false;
		protected var _inStageTipTitle:String;
		protected var _inStageTipContent:String;
		protected var _requested:Boolean = false;
		private var _assetsLoaded:Boolean = false;

		public function Base() {
			super();

		}

		override public function settle(name:String, view:View, ctrl:Controller, data:Data, superBase:SuperBase):void {
			if (this._view == null) {
				this._instanceName = name;
				this._view = view;
				if (this._view != superBase) {
					throw new Error(inheritError());
				}
				this._ctrl = ctrl;
				this._data = data;
				if (this._ctrl.hasOwnProperty(name) && hasOwnProperty("ownCtrl")) {
					this["ownCtrl"] = this._ctrl[name];
				}
			}
			this._structure = this._view.structure;
			this._popup = this._view.structure.popup;
		}

		public function get inStage():Boolean {
			var _local1:Object = this;
			return this._popup.hasView(_local1 as IView);
		}

		public function get inStageWithTip():Boolean {
			if (((this.inStage) && (this._inStageTipTitle))) {
				this._view.showTip(this._inStageTipTitle, this._inStageTipContent);
			}
			;
			return (this.inStage);
		}

		public function get ignoreKeyboardEvent():Boolean {
			return _ignoreKeyboardEvent;
		}

		protected function loadAssets(_key:String, _loadedCallback:Function, _desc:String = "", _hide:Boolean = false, _ingnoreCheck:Boolean = false, _loadedCallback2:Function = null):void {
			var self:Object;
			var lr:LoadResponder;
			var sign:String = _key;
			var callback:Function = _loadedCallback;
			var description:String = _desc;
			var hideLoading:Boolean = _hide;
			var ignoreCheck:Boolean = _ingnoreCheck;
			var callback2:Function = _loadedCallback2;
			if (this.inStage) {
				if ((callback2 is Function)) {
					(callback2());
				}
				return;
			}
			self = this;
			var allowToOpen:Function = function():Boolean {
				if (false == hideLoading) {
					_view.hideLoading();
				}
				if ((((false == ignoreCheck)) && ((_popup.allowToOpen((self as IView)) == false)))) {
					return (false);
				}
				return (true);
			}
			var handler:Function = function():void {
				if (allowToOpen()) {
					if ((callback is Function)) {
						callback();
					}
					if ((callback2 is Function)) {
						callback2();
					}
				}
			}
			if (this._view.hasResource(sign)) {
				(handler());
			} else {
				if (allowToOpen() == false) {
					return;
				}
				if (this._assetsLoaded) {
					return;
				}
				this._assetsLoaded = true;
				lr = new LoadResponder(handler, function(_arg1:String, _arg2:int):void {
					if (false == hideLoading) {
						_view.showLoading(description, _arg2);
					}
				})
				this._view.loadResources([sign], lr);
			}
		}

		public function switchSelf():void {
			if (this._ignoreKeyboardEvent) {
				return;
			}
			var _self:Object = this;
			if (this._popup.hasView((_self as IView))) {
				this["close"]();
			} else {
				this["show"]();
			}
		}

		public function get requested():Boolean {
			return this._requested;
		}
	}

}
